home *** CD-ROM | disk | FTP | other *** search
Wrap
/*Crypt.js File per l'inizializzazione dell'add-on, permette di settare ivari parametri dell'add-on a seconda del tag trovato e di far partire la codifica e la decodifica della pagina caricata nel browser. */ //nome dell'add-on usato var nome_add_on="HTTcryPt"; //variabile globale necessaria alla localizzazione dell'add-on var strBundle = null; var CRYPT = { onLoad: function() { // initialization code this.initialized = true; //gets a reference to the string bundle element added to crypt.xul by calling document.getElementById(), specifying the ID "string-bundle". strBundle = document.getElementById("string-bundle"); //seleziona la textbox per inserire testo subito document.getElementsByTagName("textbox")[0].focus(); //determina il tipo di encrypt usato CRYPT.checkTypeEncrypt(); }, //apre la finestra contenente le informazioni sull'add-on openAbout: function(){ window.open("chrome://crypt/content/about.xul", "", "chrome,centerscreen,dialog"); }, //chiude la finestra dell'add-on closeWindow: function(){ //forse non va window.opener.removeEventListener("click", arguments.callee, false); //chiude la finestra aperta window.close(); }, //Gestisce l'evento onKeyDown, per verificare se Φ stato premuto l'invio, in modo da far partire la conversione. keyPressEvent: function(e){ // Add time we got here to entropy ce();//in entropy.js var keynum; //legge il carattere premuto if(e.which){ // Netscape/Firefox/Opera keynum = e.which; } //se ho premuto l'invio, allora fai parire la conversione if(keynum==13){ CRYPT.init(); } }, //nasconde o visualizza la password, a seconda del valore della checkbox hidePwd: function(){ //determina la textbox contenente la password var tmp=document.getElementsByTagName("textbox")[0]; //se il tipo non Φ specificato, allora settalo come nascosto if(tmp.type=="") tmp.type="password"; else //altrimenti tmp.type=""; }, checkTypeEncrypt: function() { //preleva il meta relativa alla pagina da elaborare var temp=CRYPT.checkMeta(); if(temp=="AES/TXT"){ //allora la password Φ testuale document.getElementById("password").selectedIndex=0; //The method getFormattedString() gets a string with the given key name from the bundle. In addition, each occurrence of formatting code (e.g. %S) is replaced by each successive element in the supplied array. document.getElementById("found").value=strBundle.getFormattedString("resultMessage", [ "TXT", "AES" ]); } else if(temp=="AES/HEX"){ //allora la password Φ esadecimale document.getElementById("password").selectedIndex=1; document.getElementById("found").value=strBundle.getFormattedString("resultMessage", [ "HEX", "AES" ]); } else if(temp=="AES"){ //valore di default document.getElementById("found").value=strBundle.getFormattedString("resultMessage", [ "Undefined", "AES" ]); } else if(temp=="BLOWFISH"){ //valore di default document.getElementById("found").value=strBundle.getFormattedString("resultMessage", [ "Undefined", "BLOWFISH" ]); } else if(temp=="BLOWFISH/TXT"){ //allora la password Φ testuale document.getElementById("password").selectedIndex=0; document.getElementById("found").value=strBundle.getFormattedString("resultMessage", [ "TXT", "BLOWFISH" ]); } else if(temp=="BLOWFISH/HEX"){ //allora la password Φ esadecimale document.getElementById("password").selectedIndex=1; document.getElementById("found").value=strBundle.getFormattedString("resultMessage", [ "HEX", "BLOWFISH" ]); } else{ //la pagina non Φ crittata //Fetches the strings from the bundle,by calling the string bundle's getString() method, passing the appropriate key for each string. document.getElementById("found").value=strBundle.getString('resultMessageNot') //preparo l'add-on per velocizzare l'operazione di crittatura document.getElementById("encryptYN").checked=true; CRYPT.changeStyle(); return; } //lo esegue solo se la pagina Φ crittata //se la pagina Φ giα crittata, allora devo solo decrittarla, velocizzo l'operazione if(document.getElementById("encryptYN").checked){ document.getElementById("encryptYN").checked=false; CRYPT.changeStyle(); } }, init: function() { //preleva la password inserita e mette in "pwd.value" pwd=document.getElementsByTagName("textbox")[0]; //preleva i valori dei radiobox tipo_pwd_enc=document.getElementsByTagName("radio"); //preleva il tipo di crittografia usata e mette in "tipo.label" tipo=document.getElementsByTagName("menulist")[0]; //preleva il "body" crittato arrivato dal server e lo salva in "body" body=window.opener.content.document.body.innerHTML; //preleva la scelta fatta e mette in "check.checked" check=document.getElementById("encryptYN"); // Our onLoad handler kicks off the collection of entropy ce(); // Add time we got here to entropy mouseMotionEntropy(60); // Initialise collection of mouse motion entropy //chiama la funzione di calcolo CRYPT.calculate(pwd,tipo,body,check,tipo_pwd_enc); }, calculate: function(pwd,tipo,body,check,tipo_pwd_enc) { //estrae lista di div presenti nel documento var listOfDiv=window.opener.content.document.getElementsByTagName("div"); var i=0; //serve, altrimenti, dopo la chiamata a Encrypt_text, i vale 96 var divTrovato=0;//se ho trovato almeno un div valido //se non ho selezionato l'opzione di encrypt e se la password esiste if(check.checked==false && pwd.value.length>0){ //decritta il testo var temp=CRYPT.checkMeta();//estraggo i meta if(temp=="AES" || temp=="AES/TXT" || temp=="AES/HEX"){ if(listOfDiv!=null){//se la lista di div non Φ vuota for(i=0;i<listOfDiv.length;i++){ if(listOfDiv[i].className=="cryptYes"){//se la classe corrisponde divTrovato=1;//ho trovato un div testo_decrittato = Decrypt_text(pwd,listOfDiv[i].innerHTML,tipo_pwd_enc);//in jscrypt.js listOfDiv[i].innerHTML = testo_decrittato;//inserisce il testo nel div } } } if(divTrovato==0){ testo_decrittato=Decrypt_text(pwd,body,tipo_pwd_enc);//in jscrypt.js window.opener.content.document.body.innerHTML = testo_decrittato;//inserisce il testo nel body } CRYPT.removeMeta(); CRYPT.removeCheckScript(); CRYPT.checkTypeEncrypt(); } else if(temp =="BLOWFISH" || temp=="BLOWFISH/TXT" || temp=="BLOWFISH/HEX"){ var bf = new Blowfish(pwd.value,tipo_pwd_enc);// Blowfish.js if(listOfDiv!=null){//se la lista di div non Φ vuota for(i=0;i<listOfDiv.length;i++){ if(listOfDiv[i].className=="cryptYes"){//se la classe corrisponde divTrovato=1;//ho trovato un div testo_decrittato = bf.decryptBlowfish(listOfDiv[i].innerHTML,tipo_pwd_enc); listOfDiv[i].innerHTML = testo_decrittato;//inserisce il testo nel div } } } if(divTrovato==0){ testo_decrittato = bf.decryptBlowfish(body,tipo_pwd_enc); window.opener.content.document.body.innerHTML = testo_decrittato;//inserisce il testo nel body } CRYPT.removeMeta(); CRYPT.removeCheckScript(); CRYPT.checkTypeEncrypt(); } } //se ho selezionato l'opzione di encrypt e se la password esiste else if(check.checked==true && pwd.value.length>0){ //critta il testo if(tipo.label=="AES"){//quando critto, leggo il valore dalla menulist if(listOfDiv!=null){//se la lista di div non Φ vuota for(i=0;i<listOfDiv.length;i++){ if(listOfDiv[i].className=="cryptYes"){//se la classe corrisponde divTrovato=1;//ho trovato un div testo_crittato=Encrypt_text(pwd,listOfDiv[i].innerHTML,tipo_pwd_enc);//in jscrypt.js listOfDiv[i].innerHTML = testo_crittato;//inserisce il testo nel div } } } if(divTrovato==0){ testo_crittato=Encrypt_text(pwd,body,tipo_pwd_enc);//in jscrypt.js window.opener.content.document.body.innerHTML = testo_crittato;//inserisce il testo nel body } } else{ var bf = new Blowfish(pwd.value,tipo_pwd_enc);// Blowfish.js if(listOfDiv!=null){//se la lista di div non Φ vuota for(i=0;i<listOfDiv.length;i++){ if(listOfDiv[i].className=="cryptYes"){//se la classe corrisponde divTrovato=1;//ho trovato un div testo_crittato = bf.encryptBlowfish(listOfDiv[i].innerHTML,tipo_pwd_enc); listOfDiv[i].innerHTML = testo_crittato;//inserisce il testo nel div } } } if(divTrovato==0){ testo_crittato = bf.encryptBlowfish(body,tipo_pwd_enc); window.opener.content.document.body.innerHTML = testo_crittato;//inserisce il testo nel body } } CRYPT.addMeta(tipo,tipo_pwd_enc); CRYPT.addCheckScript(); CRYPT.checkTypeEncrypt(); } else//altrimenti alert(strBundle.getString('pwdErrorMessage')); }, //inserisce uno script nel documento, per far visualizzare un pop-up quando non trova l'add-on installato addCheckScript: function(){ var stringa=strBundle.getFormattedString("popUpMessage", [ nome_add_on ]) var toLink=strBundle.getString('popUpMessage2'); var link=strBundle.getString('popUpMessageLink'); scriptTag=window.opener.content.document.createElement('script');//crea un elemento script scriptTag.type='text/javascript';//definisce il tipo scriptTag.id="cryptCheckInstalledAddOn_JS";//definisce l'id //inserimento codice dello script scriptTag.text="if((navigator.userAgent).match(\""+ nome_add_on +"\")==null){document.write(\"<div id='informationbar' style='position: fixed; left: 0; width: 100%; text-indent: 5px; padding: 5px 0; background-color: lightyellow; border: 1px solid black;font: bold 12px Verdana;color: red;'>" + stringa + " <a href='" + link + "'>" + toLink + "</a></div></br></br>\")}"; //inserimento dello script nel documento window.opener.content.document.getElementsByTagName("head")[0].appendChild(scriptTag); }, //rimuove lo script dal documento decrittato, in quanto non serve pi∙ removeCheckScript: function(){ // First, get the array of script-tag elements scriptTag=window.opener.content.document.getElementsByTagName("script"); //se non Φ vuoto if(scriptTag!=null){ for(i=0;i<scriptTag.length;i++){//per ogni script trovato if(scriptTag[i].id=="cryptCheckInstalledAddOn_JS"){//se l'id corrisponde window.opener.content.document.getElementsByTagName("head")[0].removeChild(scriptTag[i]);//rimuove lo script dallo head } } } }, removeMeta: function() {//rimuove il meta se la pagina Φ stata decrittata, serve solo se dopo devo salvare la pagina // First, get the array of meta-tag elements metaP=window.opener.content.document.getElementsByTagName("meta"); //se non Φ vuoto if(metaP!=null){ for(i=0;i<metaP.length;i++){//per ogni meta trovato if(metaP[i].name==nome_add_on){//se il nome corrisponde if(metaP[i].content=="BLOWFISH" || metaP[i].content == "BLOWFISH/TXT" || metaP[i].content == "BLOWFISH/HEX" || metaP[i].content == "AES/TXT" || metaP[i].content == "AES/HEX" || metaP[i].content == "AES") window.opener.content.document.getElementsByTagName("head")[0].removeChild(metaP[i]);//rimuove il meta dallo head } } } }, checkMeta: function(){//ritorna il primo meta con le caratteristiche aspettate metaP=window.opener.content.document.getElementsByTagName("meta"); if(metaP!=null){ for(i=0;i<metaP.length;i++){ if(metaP[i].name==nome_add_on){ return(metaP[i].content);//ritorna il valore del campo content } } } }, addMeta: function(tipo,tipo_pwd_enc){//aggiunge un meta se la pagina Φ stata crittata, serve solo se dopo devo salvare la pagina // First, get the array of meta-tag elements metaP=window.opener.content.document.getElementsByTagName("meta"); //se non Φ vuoto if(metaP!=null){ for(i=0;i<metaP.length;i++){ if(metaP[i].name==nome_add_on){//se il nome corrisponde if(metaP[i].content!="BLOWFISH" && tipo.label=="Blowfish"){//serve solo per eventuali errori nella fase di creazione della pagina html if(tipo_pwd_enc[0].selected)//se la password Φ testuale metaP[i].content = "BLOWFISH/TXT";//cambia solo il contenuto else if(tipo_pwd_enc[1].selected) metaP[i].content = "BLOWFISH/HEX"; else//default metaP[i].content = "BLOWFISH"; return; } else if(metaP[i].content!="AES" && tipo.label=="AES"){//serve solo per eventuali errori nella fase di creazione della pagina html if(tipo_pwd_enc[0].selected)//se la password Φ testuale metaP[i].content = "AES/TXT"; else if(tipo_pwd_enc[1].selected) metaP[i].content = "AES/HEX"; else//default metaP[i].content = "AES"; return; } else if(metaP[i].content=="BLOWFISH" && tipo.label=="Blowfish")//se Φ gia OK non fa niente return; else if(metaP[i].content=="AES" && tipo.label=="AES")//se Φ gia OK non fa niente return; } } } //crea un nuovo elemento meta metatag=window.opener.content.document.createElement('meta'); metatag.name=nome_add_on;//gli associa il nome dell'add-on if(tipo.label=="AES"){//se ho crittato in AES if(tipo_pwd_enc[0].selected)//se la password Φ testuale metatag.content = "AES/TXT"; else if(tipo_pwd_enc[1].selected) metatag.content = "AES/HEX"; else//default metatag.content=tipo.label.toUpperCase(); } else{//se ho crittato in BLOWFISH if(tipo_pwd_enc[0].selected)//se la password Φ testuale metatag.content = "BLOWFISH/TXT"; else if(tipo_pwd_enc[1].selected) metatag.content = "BLOWFISH/HEX"; else//default metatag.content=tipo.label.toUpperCase(); } //aggiunge il meta nel documento window.opener.content.document.getElementsByTagName("head")[0].appendChild(metatag); }, //genera una chiave premendo l'apposito tasto genKey: function(){ //determina il tipo di password scelto tipo_pwd_enc=document.getElementsByTagName("radio"); if(tipo_pwd_enc[0].selected)//se la password Φ testuale suffix=strBundle.getString('genKeySuffixTxt'); else suffix=strBundle.getString('genKeySuffixHex'); //apre una finestra "alert" contenente la password alert(strBundle.getFormattedString("genKeyMessage", [ Generate_key(tipo_pwd_enc), suffix ])); }, //cambia lo stile di visualizzazione di alcuni elementi nella UI, rendendoli abilitati o no changeStyle: function() { document.getElementsByTagName("menulist")[0].disabled = ! document.getElementsByTagName("menulist")[0].disabled; document.getElementById("encoding").disabled = ! document.getElementById("encoding").disabled; document.getElementById("gen").disabled = ! document.getElementById("gen").disabled; }, //resetta l'add-on, come se fosse stato appena aperto resetDefault: function() { //svuota la textbox document.getElementsByTagName("textbox")[0].value=""; //seleziona il tipo di password come testuale, andando a prendere il primo groupbox document.getElementsByTagName("radiogroup")[0].selectedIndex=0; //deseleziona il checkbox di hide/show password if(document.getElementById("pwdHS").checked==true){ document.getElementById("pwdHS").checked=false; CRYPT.hidePwd();//devo cambiare lo stile della textbox } //seleziona il tipo di crittografia (AES) document.getElementsByTagName("menulist")[0].selectedIndex =0; //seleziona il tipo di codifica come codegroup, andando a prendere il secondo groupbox document.getElementsByTagName("radiogroup")[1].selectedIndex=0; //seleziona la textbox per inserire testo subito document.getElementsByTagName("textbox")[0].focus(); } }; //quando apro l'add-on, associagli l'evento onLoad window.addEventListener("load", function(e) { CRYPT.onLoad(e); window.removeEventListener("load", arguments.callee, false);}, false);